<?php

	namespace Phptricks\app\controllers\settings;

	/**
	 *  phptricks Framework 
	 *  link http://phptricks.net/Framework
	 *  date start 2014
	 */
	use Phptricks\app\controllers\base\base as base;
	use Phptricks\app\models\groups\groups as groups_model;

	class settings extends base{
		
		public $groups_model = null;
		public function __construct(){
			parent::__construct();
			$this->groups_model = groups_model::getinstance();
		}

		public function admin_index(){

			$data = $this->settings_model->getsettings();
			$this->view->assign('data', $data);
			
			$users_groups = $this->groups_model->get_groups();
			$this->view->assign('users_groups', $users_groups);
			
			$this->view->assign('page_title', $this->lang['settings']);
			$this->view->display('settings.tpl');
		}

		public function admin_update(){
			$this->form_validation->post(array(
				/* Site Settings */
				'site_name' => 'isnull|minlength:5|maxlength:200',
				'site_url' => 'isnull|minlength:5|maxlength:200',
				'site_language' => 'isnull',
				'site_description' => 'isnull',
				'site_keywords' => 'isnull',
				'site_mail' => 'isnull|checkmail',
				'site_fb' => '',
				'site_tw' => '',
				'site_googleplus' => '',
				'site_close' => 'isnull|digit',
				'site_msg' => 'isnull|maxlength:200',
				/* Search Engine Settings */
				'search_active' => 'isnull|digit',
				/* User Interface */
				'site_default_theme_admin' => 'isnull',
				'site_default_theme' => 'isnull',
				/* Users Controller */
				'site_activate_registration' => 'isnull|digit',
				'site_registration_msg' => '',
				'site_default_group_guest' => 'isnull|digit',
				'site_default_group' => 'isnull|digit',
				'pass_max' => 'isnull|digit',
				'pass_min' => 'isnull|digit',
				'users_max' => 'isnull|digit',
				'users_min' => 'isnull|digit',
				/* Tweets Settings */
				'tried_active' => 'isnull|digit',
				'number_of_trieds_in_minute' => 'isnull|digit',
				'tried_maxlength' => 'isnull|digit',
				'tried_minlength' => 'isnull|digit',
				'comment_active' => 'isnull|digit',
				'comment_maxlength' => 'isnull|digit',
				'comment_minlength' => 'isnull|digit',
			));
			$this->form_validation->fetch();
			$submit = $this->form_validation->submit();
			if ($submit !== true) {
				$error = implode('<br>', $this->form_validation->_error);
				$this->view->assign('error', $error);
				$this->view->assign('error_type', 'danger');
				$this->view->display('header.tpl');
				$this->view->display('footer.tpl');
				return false;
			}
			$array_data = $this->form_validation->_array_data;
			if ($this->settings_model->updatesettings($array_data)) {
				$this->redirect('admin/settings/');
			}
		}

	}
	